package de.fhb.itunes.manager.mail.Template;

import de.fhb.itunes.manager.Config;
import de.fhb.itunes.manager.mail.Helper_File;



public class Template {
	private int nr;
	private String text;
	private String titel;
	private String bild_url;
	private String htmlpfad;
	private String html;
	private HTML_Templates layout;

	public Template(HTML_Templates art) {

		this.layout = art;
		this.text = "Text";
		this.bild_url = "http://www.dibiasibus.it/uploads/pics/no_image.jpg_06.png";
		this.titel = "Titel";
		this.nr = -1;
	}
	public Template(String text) {

		this.layout = HTML_Templates.textonly;
		this.text = text;
		this.bild_url = "";
		this.titel = "";
		this.nr = -1;
	}

	public Template(HTML_Templates art, String text, String titel,
			String bild_url) {
		this.layout = art;
		this.text = text;
		this.titel = titel;
		if (bild_url == null || bild_url == "") {
			this.bild_url = "http://www.dibiasibus.it/uploads/pics/no_image.jpg_06.png";
		} else {
			this.bild_url = bild_url;
		}
		this.nr = -1;

	}
	public Template( String text, String titel,String bild_url){
		this(random(),text,titel,bild_url);
	}
	
	private static HTML_Templates random() {
		HTML_Templates ret = null;
		int zahl;
		double i;
		do {

			i = Math.random();
			zahl = (int) (i * 10);
		} while (zahl < 1 || zahl > 3);
		switch (zahl) {
		case 1:
			ret = HTML_Templates.fullwidthImage;
			break;
		case 2:
			ret = HTML_Templates.textWithLeftAlignedImage;
			break;
		case 3:
			ret = HTML_Templates.textWithRightAlignedImage;
			break;
		}
		return ret;
	}
	public String getHTML() {
		pfadLaden();
		htmlparsen();
		return this.html;
	}

	private void pfadLaden() {
		Config config = new Config();
		switch (layout) {
		case fullwidthImage:
			htmlpfad = config.getProperties()
					.getProperty("pfad_fullwidthImage");
			break;
		case textonly:
			htmlpfad = config.getProperties().getProperty("pfad_textonly");
			break;
		case textWithRightAlignedImage:
			htmlpfad = config.getProperties().getProperty(
					"pfad_textWithRightAlignedImage");
			break;
		case textWithLeftAlignedImage:
			htmlpfad = config.getProperties().getProperty(
					"pfad_textWithLeftAlignedImage");
			break;
		/*
		 * case textTwoColloums: htmlpfad = config.getProperties().getProperty(
		 * "pfad_textTwoColloums"); break; case threeSideBySideimages: htmlpfad
		 * = config.getProperties().getProperty( "pfad_threeSideBySideimages");
		 * break;
		 */
		default:
			htmlpfad = "";
			break;
		}

	}

	private void htmlparsen() {
		html = Helper_File.ladeDatei(htmlpfad);
		if (this.html != null) {
			if (this.titel != null && this.text != null
					&& this.bild_url != null) {
				this.html = this.html.replaceAll("replaceTitel", this.titel);
				this.html = this.html.replaceAll("replaceText", this.text);
				this.html = this.html.replaceAll("replaceBild_Pfad",
						this.bild_url);
			}
		} else {
			html = "";
		}
	}

	public void readInformation(){
		
	}
	
	public int getNr() {
		return nr;
	}

	public void setNr(int nr) {
		this.nr = nr;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getTitel() {
		return titel;
	}

	public void setTitel(String titel) {
		this.titel = titel;
	}

	public String getBild_url() {
		return bild_url;
	}

	public void setBild_url(String bild_url) {
		this.bild_url = bild_url;
	}

}
